/*
 * Copyright 2007 Project ELERFED
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package nlpeap.ml.svm;

import java.io.UnsupportedEncodingException;

import edu.hit.irlab.coref.CRConfigProperties;


/** native interface to SVMLight-TK
 *  modified by chuter on Jul 5th, 2010, at 3:04PM
 */
class SVMLightTK
{
    static {
    	System.loadLibrary(CRConfigProperties.getInstance().getSvmLibrary());
    }
    final private int modelHandle;
    final private double modelThreshold;
    
    /** loads a model from a file */
    public SVMLightTK(String modelFile)
    {
		modelHandle=load_model(modelFile);
		modelThreshold=get_threshold();
    }
    
    /** given an instance in SVMLight-TK format,
     *  returns the classification
     */
    public double classify(String instance)
    {
	return classify_instance(modelHandle, instance);
    }

    public double getThreshold()
    {
	return modelThreshold;
    }
    private static native int load_model(String modelFile);
    private static native double get_threshold();
    private static native double classify_instance(int modelNumber,
						   String instance);

    public static void main(String[] args)
    {
	String test_input="-1 |BT| (s2 (S1 ) (S1 )) |ET|";
//	SVMLightTK model=new SVMLightTK("/home/th/liyaobing/bart/models/coref/idc1_trees3.svmltk");
	SVMLightTK model=new SVMLightTK("idc1_trees3.svmltk");
	System.out.println("SCORE model "+0+": "+model.classify(test_input));
    }
}
